{% extends './base.html' %}
{% block title %}写随说{% endblock %}
{% block header %}

{% endblock %}
{% block footer %}
    <script>
        // 提交
        $('#form-edit').submit(function (e) {
            e.preventDefault()
            var mood = $(this).find('select[name=mood]').val()
            var content = $(this).find('textarea[name=content]').val()
            if (mood && content) {
                $ajax.post({
                    url: location.pathname,
                    data: {
                        mood: mood,
                        content: content,
                    },
                    success: function (res) {
                        lightyear.loading('hide');
                        if (res.code === 200) {
                            lightyear.notify(res.msg + '页面即将自动跳转~', 'success', 1000);
                            setTimeout(function () {
                                location.replace('/cms/talks/')
                            })
                        } else {
                            lightyear.notify(res.msg, 'danger', 1000);
                        }
                    }
                })
            } else {
                lightyear.notify('还有未填项~~', 'danger', 1000)
            }
        })
    </script>
{% endblock %}
{% block main %}
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                    <form action="#" method="post" class="row" id="form-edit">
                        <div class="form-group col-md-12">
                            <label for="mood">心情</label>
                            <div class="form-controls">
                                <select name="mood" class="form-control" id="mood">
                                    <option value="">请选择心情</option>
                                    {% for mood in moods %}
                                        <option value="{{ mood.id }}">{{ mood.name }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <label>内容</label>
                            <textarea class="form-control" name="content" rows="5"
                                      placeholder="内容"></textarea>
                        </div>
                        <div class="form-group col-md-12">
                            <button type="submit" class="btn btn-primary" id="ajax-btn">提交</button>
                            <button type="reset" class="btn btn-default">重置</button>
                        </div>
                    </form>

                </div>
            </div>
        </div>

    </div>
{% endblock %}

